/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.reportlose.controller
 * FILE    NAME: ReportLoseDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */ 
package com.jodinfo.outmirror.api.reportlose.controller;

import java.math.BigInteger;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.hero.common.web.context.UserContext;
import com.hero.core.constant.SysConstant;
import com.hero.core.entity.IPlatformUser;
import com.hero.core.entity.ResponseEntity;
import com.jodinfo.outmirror.api.reportlose.entity.ReportLoseEntity;
import com.jodinfo.outmirror.api.reportlose.service.ReportLoseBizService;



@Controller
@RequestMapping(value = "/ReportLoseAdmin")
public class ReportLoseController  {
	
@Resource(name="reportLoseBizService")
private ReportLoseBizService ReportLoseBizService;
/**
*  list数据源
* 
* */
@RequestMapping(value = "/List")
@ResponseBody
public String ReportLoseList(ReportLoseEntity ReportLoseEntity) {
	if(ReportLoseEntity==null){
		ReportLoseEntity = new ReportLoseEntity();
		ReportLoseEntity.setPageIndex(SysConstant.DEFAULT_PAGEINDEX);
		ReportLoseEntity.setPageSize(SysConstant.DEFAULT_PAGESIZE);
	}
	ReportLoseEntity.setCurrentUser(UserContext.getUser());
	if(StringUtils.isEmpty(ReportLoseEntity.getBranchOrgId()) && StringUtils.isEmpty(ReportLoseEntity.getOfficeOrgId())){
		ReportLoseEntity.setBranchOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
		ReportLoseEntity.setOfficeOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
	}
	String str = ReportLoseBizService.queryListForPageReportLose(ReportLoseEntity);
	return str;
}
/**
* ReportLoseEntity List页面
* 
* */
@RequestMapping(value = "/ListPage")
public ModelAndView ReportLoseListPage(ReportLoseEntity ReportLoseEntity,HttpServletRequest request) {
	
	return new ModelAndView(returnPath("ReportLoseList"));
}
/**
* ReportLoseEntity详细页 
* 
* */
@RequestMapping(value = "/EditPage")
public ModelAndView ReportLoseEditPage(ReportLoseEntity ReportLoseEntity) {
	
	return new ModelAndView(returnPath("ReportLoseAdd"));
}
/**
 * 查询ReportLoseEntity
 * 
 * */
@RequestMapping(value = "/queryByID")
public @ResponseBody String findReportLoseData(HttpServletRequest request) {
	String id = request.getParameter("id");
	ReportLoseEntity ReportLoseEntity =  ReportLoseBizService.queryById(new BigInteger(id));
	return JSON.toJSONString(ReportLoseEntity); 
}

/**
 * 保存或更新ReportLose 
 * 
 * */
@RequestMapping(value = "/saveReportLose")
public @ResponseBody String saveReportLoseData(@RequestBody ReportLoseEntity ReportLoseEntity) {
	ResponseEntity rs = null;
	if(ReportLoseEntity!=null){
		ReportLoseEntity.setCurrentUser(UserContext.getUser());
		if(ReportLoseEntity.getId()!=null){
			rs = ReportLoseBizService.updateReportLose(ReportLoseEntity);
		}else{
			rs = ReportLoseBizService.addReportLose(ReportLoseEntity);
		}
	}
	return JSON.toJSONString(rs);
}
/**
 * 导出ReportLoseEntity
 * @author weiwei
 * @date 2015-7-09  下午2:13:28
 * @return
 */
@RequestMapping(value = "/exportReportLoseExcel")
public void exportReportLoseExcel(ReportLoseEntity ReportLoseEntity,HttpServletResponse response) {
	if(ReportLoseEntity==null){
		ReportLoseEntity = new ReportLoseEntity();
	}
	ReportLoseEntity.setCurrentUser(UserContext.getUser());
	if(StringUtils.isEmpty(ReportLoseEntity.getBranchOrgId()) && StringUtils.isEmpty(ReportLoseEntity.getOfficeOrgId())){
		ReportLoseEntity.setBranchOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
		ReportLoseEntity.setOfficeOrgId(((IPlatformUser)UserContext.getUser()).getOrgId());
	}
	ReportLoseBizService.exportReportLose(ReportLoseEntity, response);
}


 /**
 * 
 * 批量删除
 * @author weiwei
 * @date 2017年3月13日 下午2:48:57
 * @param ReportLoseEntity
 * @return
 */
@RequestMapping(value = "/batchDelReportLose")
public @ResponseBody String batchDelReportLose(ReportLoseEntity ReportLoseEntity) {
	ResponseEntity rs = null;
	rs = ReportLoseBizService.batchDelReportLose(ReportLoseEntity);
	return  JSON.toJSONString(rs);
}
/**
 * 定义
 * 
 */
private final String MODULE_PATH = "/reportlose/";

//返回路径
private String returnPath(String jspName) {
	return MODULE_PATH + jspName;
}
}
